#pragma once

#include <iostream>
#include <vector>

class Util
{
public:
    // aaaa\r\nbbbbb\r\nccc\r\n\r\n
    static void cutString(std::string s, const std::string &sep, std::vector<std::string> *out)
    {   // 剪切读取到的请求,static使得类名直接访问方法函数
        std::size_t start = 0;
        while (start < s.size())
        {
            auto pos = s.find(sep, start); // 从start开始查找sep分隔符
            if (pos == std::string::npos) // 找不到,break
                break;
            std::string sub = s.substr(start, pos - start); // 找到了,子串截取
            out->push_back(sub); // 截取到的子串push进vector
            start = start + sub.size() + sep.size(); // 让start指向分隔符右侧,不断循环
        }
        if (start < s.size()) // 后面还有内容也push
            out->push_back(s.substr(start));
    }
};